import { spawn } from 'child_process'
import { Controller, Post, Get, Body, Query, UsePipes } from '@nestjs/common'

@Controller()
export class DeployController {
  @Get('/deploy/run')
  deploy() {
    const command = 'java'
    const cmd = `-jar ${process.cwd()}/deploy/deploy.jar -A yunxi-rc-review-oa -B release -P weihai -E stable`
    const args = cmd.split(' ')
    const javaProcess = spawn(command, args)

    javaProcess.stdout.on('data', (data) => {
      console.log('out ——>', data.toString())
    })

    javaProcess.stderr.on('data', (data) => {
      console.log('err ——>', data.toString())
    })

    javaProcess.on('close', (code) => {
      console.log('close ——>', code)
    })
  }
}
